<template>
  <el-row>
    <el-col :xl="5" :lg="8" :md="12" :sm="12" :xs="24">
      <el-form :model="form" ref="form" label-width="110px" size="small" :rules="rules">
        <el-form-item label="代理商编号：" prop="org_no">
          <el-input v-model="form.org_no" :maxlength="10"></el-input>
        </el-form-item>
        <el-form-item label="进件秘钥：" prop="token_key">
          <el-input v-model="form.token_key" :maxlength="40"></el-input>
        </el-form-item>
        <el-form-item label="交易回调秘钥：" prop="notify_key">
          <el-input v-model="form.notify_key" :maxlength="40"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" class="fr" @click="handleClickOnSubmit">确认保存</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>
import { channelLeInit, channelLeUpdate } from '@/api/setting'

export default {
  data() {
    return {
      form: {
        org_no: '',
        notify_key: '',
        token_key: ''
      },
      rules: {
        org_no: [{ required: true, trigger: 'blur', message: '必须填写哦~' }],
        token_key: [{ required: true, trigger: 'blur', message: '必须填写哦~' }],
        notify_key: [{ required: true, trigger: 'blur', message: '必须填写哦~' }]
      }
    }
  },
  methods: {
    handleDocumentInit() {
      channelLeInit().then(res => {
        if (res.data.errorCode === 0) {
          this.form.org_no = res.data.result.org_no
          this.form.token_key = res.data.result.token_key
          this.form.notify_key = res.data.result.notify_key
        } else {
          this.$message.error(res.data.errorMsg)
        }
      })
    },
    handleClickOnSubmit() {
      channelLeUpdate(this.form).then(res => {
        if (res.data.errorCode === 0) {
          this.$message.success(res.data.errorMsg)
        } else {
          this.$message.error(res.data.errorMsg)
        }
      })
    }
  },
  created() {
    this.handleDocumentInit()
  }
}
</script>
